import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from project_utils.get_washer_mappings import match_mappings, not_match_mappings
from config import *
from concat_sql.washer_column_mapping import insert_washer_mapping
import datetime
import multiprocessing


if __name__ == '__main__':
    tablename = hbase_map_table
    mapping1 = match_mappings(tablename)
    mapping2 = not_match_mappings(tablename)
    mappings = {**mapping1, **mapping2}
    today = datetime.datetime.today()
    # 历史所有日期
    begin = datetime.date(WASHER_START_YEAR, WASHER_START_MONTH, WASHER_START_DAY)
    end = datetime.date(WASHER_END_YEAR, WASHER_END_MONTH, WASHER_END_DAY)
    date_list = [(begin + datetime.timedelta(days=i)).strftime("%Y-%m-%d") for i in range((end - begin).days + 1)]
    results = []
    pool = multiprocessing.Pool(processes=30)
    for date in date_list:
        for model, column_mapping in mappings.items():
            # insert_washer_mapping(model, column_mapping, date)
            result = pool.apply_async(insert_washer_mapping, (model, column_mapping, date))
            results.append(result)
    pool.close()
    pool.join()
